#pragma once
#include <vector>
#include "xkImgBit.h"
#include "xkImgCheck.h"
#include "xkImgBit16.h"
#include "xkImgBit8.h"

#include "DDirectDisplay.h"
#include "DDReadWriteFile.h"
#include "DDThread3.h"

#include "DrawInfoDefine.h"


class xhImagePro : public DDThread3
{
public:
	xhImagePro(void);
	~xhImagePro(void);

public:
	//init
	int Initialize();
	int UnInitialize();
	//set parent hwnd
	int SetHwnd(HWND hWnd,zkScreenMon *pScreen=NULL);
	int RegOnDrawCallBack(OnDrawCallBackFun funCallBack,void *pContext);
	int RegMsgCallBack(ImgProMsgCallBackFun funCallBack,void *pContext);

public:
	//open file,or use SetOrgBuffer
	int LoadFile(char *pFileName);
	//set original bitmapinfo and data 
	int SetImgBuffer(zkImgBitInfo *pImgInfo,BOOL bShareMem = TRUE,BOOL bShowImg = TRUE);

public:
	int GetImageSize(int &nWidth,int &nHeight);

public:
	int Restore();
	//set process mode and parameter
	int Operate(DWORD dwProMode,void *pVoid = NULL);

public:
	//draw data
	int	Draw(void *pVoid = NULL);
	int ImageCtrl(DWORD dwType,void *pVoid = NULL);
	//
	int SaveDispToFile(char *pFileName,void *pVoid = NULL,int nToJpg = 0);

public:
	//get image information
	int GetImgBuffer(zkImgBitInfo **ppImgInfo);

public:
	//get return information,reserve
	int GetGrayValue(int x,int y,DWORD &dwGray);
	//
	int GetLineGray(POINT tStart,POINT tEnd,zkImgLineGray **ppLineGray);
	//get the image Histogram information
	int GetHistogramInfo(zkImgHistogram **ppHistogram);

public:
	//save the file
	int SaveFile(char *pFileName,int nExType,void *pVoid = NULL);

public:
	//draw mark
	int DrawMark(void *pVoid = NULL);

private:
	void DefaultDisplayPalette(zkImgBitInfo *pImgInfo);
	int  LoadDataToDisp();
	int  GetExDataFromFile(char *pFileName);
	int  SaveExDataFromFile(char *pFileName);

private:
	virtual int DDThdDispatch(HANDLE hExitEvent = NULL);


public:
	DWORD                m_dwContext;
	void                *m_pContext;
	ImgProMsgCallBackFun m_funMsgCallBack;

private:
	DDCriticalSection m_Sect;

private:
	xkImgBit  *m_pImgBit;
	xkImgBit16 m_xImgBit16;
	xkImgBit8  m_xImgBit8;

private:
	DDirectDisplay m_xDisp;
	zkImgDraw      m_xImgDraw;

private:
	std::vector<DWORD> m_arProMode;

private:
	zkImgBitInfo   m_xImgBitInfo;
	zkImgCapParam  m_xImgCapParam;
	BYTE           m_cImgAssBuf[DEFINE_ASS_PARAM_SIZE];
	zkImgAssParam *m_pImgAssParam;
	BYTE          *m_pImgAssData;

	DDReadWriteFile m_xFile;

private:
	int   m_nPicSize;
	BYTE *m_pPicBuffer;

public:
	int  m_nSaveFile;

};
